home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gui4cli / dir / dir.gfxcon < prev    next >
Text File  |  1999-04-29  |  6KB  |  321 lines

  1. G4C  
  2.  
  3. ; dir.gfxcon - by dck January 1997
  4.  
  5. ; A GUI for the great picture format converter :
  6. ; GfxCon V1.7 © Dirk Farin / farindk@trick.informatik.uni-stuttgart.de 
  7. ; (Available on Aminet)
  8.  
  9. ; Looks for GFXcon under the name contained in variable $DEF.GFXCON
  10.  
  11.  
  12. WINBIG 180 15 200 166  "GfxCon V1.7"
  13. WinType 11110001
  14.  
  15. xOnLoad
  16. ifexists file $*DEF.GFXCON            ; you MUST have configured dir.gc
  17.     ; You're my kind of guy..
  18. else
  19.     EZReq "GFXcon not found!\nPlease configure\nDir.gc correctly." "OK" ""
  20.     guiquit dir.gfxcon
  21.     stop
  22. endif
  23. format = ILBM                       ; our variables
  24. colors = "" 
  25. bw     = ""
  26. flip   = ""
  27. rot    = ""
  28. x      = 320
  29. y      = 250
  30. size   = ""
  31. file   = ""
  32. mode   = FILES
  33. gosub dir.gfxcon FileMode
  34. guiopen dir.gfxcon
  35.  
  36. xOnClose
  37. delvar  #?
  38. guiquit dir.gfxcon
  39.  
  40. xRoutine FileMode
  41. setgad dir.gfxcon 1/13  HIDE
  42. setgad dir.gfxcon 21/25 SHOW
  43. redraw dir.gfxcon
  44.  
  45. xRoutine ConvertMode
  46. setgad dir.gfxcon 1/13  SHOW
  47. setgad dir.gfxcon 21/25 HIDE
  48. redraw dir.gfxcon
  49.  
  50. XCYCLER 0 0 200 14  "" mode
  51. cstr "Choose/Add Files"      FILES
  52. Cstr "Converting Options"    CONVERT
  53. if $mode = CONVERT
  54.    gosub dir.gfxcon ConvertMode
  55. else
  56.    gosub dir.gfxcon FileMode
  57. endif
  58.  
  59. ;------------------------------- PRETTY OBVIOUS OPTIONS GADGETS
  60.  
  61. XCYCLER 70 15 125 14  Format format
  62. GadID 1
  63. cstr ILBM ILBM
  64. cstr GIF  GIF
  65. cstr JPEG JPEG
  66. cstr PCX  PCX
  67. cstr PostScript Postscript
  68. cstr RGB-Raw   RGB-Raw
  69.  
  70.  
  71. XCYCLER 70 30 125 14  Colors colors
  72. GadId 2
  73. cstr Default ""
  74. cstr 16      16
  75. cstr 32      32
  76. cstr 128     128
  77. cstr 256     256
  78. cstr 2       2
  79. cstr 4       4
  80. cstr 8       8
  81.  
  82. XCYCLER 70 45 125 14  Type bw
  83. GadId 3
  84. cstr Default    ""
  85. cstr GRAYSCALE  GRAYSCALE
  86. cstr BW         BW
  87. cstr INVERT     INVERS
  88. cstr "NO Red"   NORED
  89. cstr "NO Green" NOGREEN
  90. cstr "NO Blue"  NOBLUE
  91.  
  92. XCYCLER 70 60 125 14  Flip flip
  93. gadid 11
  94. Cstr None  ""
  95. cstr "Flip X" FLIPX
  96. cstr "Filp Y" FLIPY
  97. cstr "Flip XY" "FLIPX FLIPY"
  98.  
  99. XCYCLER 70 75 125 14  Rotate rot
  100. gadid 12
  101. cstr None ""     
  102. cstr "90 Left"   ROTATELEFT
  103. cstr "90 Right"  ROTATERIGHT
  104.  
  105. ; NOT IMPLEMENTED YET
  106. ; slider contrast CONTRAST 0-100
  107. ; slider brightness BRIGHTNESS 0-255
  108.  
  109. ;---- Size
  110.  
  111. XCYCLER 70 90 125 14  Size size
  112. gadid 4
  113. cstr Same    ""
  114. cstr BOXFIT  BOXFIT
  115. cstr SIZE    SIZE
  116. if $size = NONE
  117.    setgad dir.gfxcon 5 OFF
  118.    setgad dir.gfxcon 6 OFF
  119. else
  120.    setgad dir.gfxcon 5 ON
  121.    setgad dir.gfxcon 6 ON
  122. endif
  123.  
  124. ; -- Size textin gadgets
  125. XTEXTIN 70 105 61 14  "" x 320 10
  126. gadid 5
  127. SetGad dir.gfxcon 6 ON
  128.  
  129. XTEXTIN 135 105 59 14  "" y 250 10
  130. gadid 6
  131.  
  132. ; -------------------- Status Boxes
  133.  
  134.  
  135. TEXT 5 112 40 10  "Status:" 20 NOBOX
  136. gadid 7
  137.  
  138. TEXT 4 123 190 12  "No Files" 130 BOX
  139. GadID 8
  140.  
  141. Gauge 4 136 190 12 IN BUTTON 3 0 0
  142. gadid 13
  143.  
  144. xPIPE pipe:gfxcon ON
  145. if $mode = CONVERT
  146. and $finishflag = 0
  147.    update dir.gfxcon 8 '$$PIPE'
  148. endif
  149.  
  150. ;--------------------- LISTVIEW SHOWING FILES TO CONVERT
  151.  
  152. XLISTVIEW 0 15 198 132  "" file "" 10 MULTI
  153. gadid 21
  154.  
  155. XBUTTON 0 150 50 14  View
  156. gadid 25
  157. lvuse dir.gfxcon 21
  158. lvmulti first
  159. while $file > ""
  160.    *RUNMODE  = 'run >nil:'
  161.    *FILENAME = $file
  162.    gosub viewfile.g ViewFile
  163.    lvmulti next
  164. endwhile
  165.  
  166. XBUTTON 50 150 50 14  Add            ; add files selected from dir.gc
  167. gadid 22
  168. id = $$lv.id
  169. lvuse dir.gc $id
  170. lvmulti first
  171. while $dir.gc/lv_file > ""
  172.    lvuse   dir.gfxcon 21
  173.    lvadd   $dir.gc/lv_file
  174.    lvuse   dir.gc $id
  175.    lvmulti off
  176.    lvmulti next
  177. endwhile
  178.  
  179. XBUTTON 100 150 50 14  Del           ; delete selected files
  180. gadid 23
  181. lvuse dir.gfxcon 21
  182. lvmulti first
  183. while $file > ""
  184.    lvdel -1
  185.    lvmulti first        ; use first again since last first was deleted
  186. endwhile
  187.  
  188. XBUTTON 150 150 50 14  Clr
  189. gadid 24
  190. lvuse dir.gfxcon 21
  191. lvclear
  192.  
  193.  
  194. ;-------------------- Cancel the relaunch of gfxcon
  195.  
  196. XBUTTON 100 150 95 14  CANCEL 
  197. gadfont topaz.font 8 010
  198. gadid 9
  199. flag = 1
  200.  
  201.  
  202. ;-------------------- This is where we do our stuff!
  203.  
  204. XBUTTON 5 150 95 14  "Convert"
  205. gadid 10
  206. gadfont topaz.font 8 010
  207. flag = 0
  208. finishflag = 0
  209. lvuse dir.gfxcon 21
  210. count = 0
  211. total = $$lv.tot
  212. update dir.gfxcon 13 0    ; gauge
  213. lvgo #0
  214. cfile = $$lv.rec
  215. if $cfile > ""
  216.    gosub dir.gfxcon addextension
  217.    lvdel  0
  218.    update dir.gfxcon 7 Converting:
  219.    update dir.gfxcon 8 $cfile
  220.    gosub  dir.gfxcon makecom
  221.    setstack 20000
  222.    ; say '$*DEF.GFXCON >pipe:gfxcon $cfile $com \n'
  223.    Launch 1 '$*DEF.GFXCON >pipe:gfxcon $cfile $com NOPROGRESS'
  224.    setstack 4000
  225. endif
  226.  
  227. ; This is where the Launch command will return to when the program
  228. ; it has run has finished executing. We then tell it to do it again
  229.  
  230. xOnReturn 1
  231. if $mode = CONVERT
  232.    update dir.gfxcon 13 0
  233.    update dir.gfxcon 7  Status:
  234.    update dir.gfxcon 8  Finished
  235. endif
  236. if $flag = 1
  237.    stop
  238. endif
  239. lvuse dir.gfxcon 21
  240. lvgo #0
  241. cfile = $$lv.rec
  242. if $cfile > ""
  243.    ++count
  244.    temp  == $count * 100
  245.    ratio == $temp / $total
  246.    update dir.gfxcon 13 $ratio    ; gauge
  247.    gosub dir.gfxcon addextension
  248.    lvdel  0
  249.    update dir.gfxcon 7 Converting:
  250.    update dir.gfxcon 8 $cfile
  251.    gosub  dir.gfxcon makecom
  252.    setstack 20000
  253.    ; say '$*DEF.GFXCON >pipe:gfxcon $cfile $com \n'
  254.    Launch 1 '$*DEF.GFXCON >pipe:gfxcon $cfile $com NOPROGRESS'
  255.    setstack 4000
  256. else
  257.    update dir.gfxcon 8 "Finished."
  258.    finishflag = 1
  259. endif
  260.  
  261.  
  262. ; ------------ Routine to form command line
  263.  
  264. xroutine makecom
  265. com = 'FORMAT $format'
  266. if $colors > ""
  267.    appvar com ' COLORS $colors'
  268. endif
  269. if $bw > ""
  270.    appvar com ' $bw'
  271. endif
  272. if $flip > ""
  273.    appvar com ' $flip'
  274. endif
  275. if $rot > ""
  276.    appvar com ' $rot'
  277. endif
  278. if $size > ""
  279.    appvar com ' $size $x $y'
  280. endif
  281.  
  282.  
  283. xROUTINE addextension
  284. ; if file doesn't have an extension, we must add one
  285. extract cfile ext ex
  286. if $ex > ""
  287.    return
  288. else
  289.    oldname = $cfile
  290.    ; find out extension according to file type
  291.    if $cfile H= "FORM????ILBM"
  292.    or $cfile H= "FORM??ILBM"
  293.        exname = .iff
  294.    elseif $cfile H= GIF
  295.        exname = .gif
  296.    elseif $cfile H= "??????JFIF"
  297.        or $cfile H= "ÿØÿÄ"
  298.        exname = .jpg
  299.    else  ; we don't know what it is
  300.        exname = .ext
  301.    endif
  302.    ; handle possible quoted string
  303.    if $cfile[-1][1] = '"'
  304.       cutvar cfile cut char -1 ''
  305.       appvar cfile '$exname\"'
  306.    else
  307.       appvar cfile '$exname'
  308.    endif
  309.    rename $oldname $cfile
  310. endif
  311.  
  312. ; --------------
  313. ; This is where we'll end up if anything goes wrong..
  314. ; i.e. such as GFXcon not finding the file and returning an error status
  315.  
  316. xOnFail
  317. EZReq  "An error occured.\nClick on Convert to continue." "OK" ""
  318.  
  319.  
  320. RESIZE_BIG 180 15 257 187 DIR.GFXCON
  321.